package com.zhouxiaoge.proxy.cglib;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

/**
 * @author 周明阳
 * mail:gqzmy@outlook.com
 * 时间:2018-03-12 11:25
 */

public class SampleClass {

    public void test() {
        System.out.println("Hello World!");
    }

    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(SampleClass.class);
        enhancer.setCallback((MethodInterceptor) (o, method, objects, methodProxy) -> {
            System.out.println("before method run...");
            Object o1 = methodProxy.invokeSuper(o, objects);
            System.out.println("after method run...");
            return o1;
        });
        SampleClass sampleClass = (SampleClass) enhancer.create();
        sampleClass.test();

    }

}
